package com.adinnet.admin.system.service.impl;

import com.adinnet.admin.system.mapper.SysMenuMapper;
import com.adinnet.admin.system.model.SysMenu;
import com.adinnet.admin.system.service.SysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 权限表 服务实现类
 * </p>
 *
 * @author sunjianbo
 * @since 2019-05-17
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {

    @Override
    public List<SysMenu> listByUserId(Integer userId) {
        return baseMapper.listByUserId(userId);
    }

    @Override
    public List<SysMenu> listByRoleId(Integer roleId) {
        if (roleId == null) {
            return new ArrayList<>();
        }
        return baseMapper.listByRoleId(roleId);
    }


    @Override
    public List<SysMenu> listByRoleIds(List<Integer> roleIds) {
        if (roleIds == null || roleIds.size() == 0) {
            return new ArrayList<>();
        }
        return baseMapper.listByRoleIds(roleIds);
    }

    @Override
    public List<String> buttonListByUserId(Map<String, Object> papams) {
        List<String> buttonList = new ArrayList<>();
        List<SysMenu> sysMenuList =  baseMapper.buttonListByUserId(papams);
        for (SysMenu sysMenu : sysMenuList) {
            buttonList.add(sysMenu.getPermission());
        }
        return buttonList;
    }
}
